package administration;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class AddAdminServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	public void doPost(HttpServletRequest req, HttpServletResponse resp){
		
		String un = req.getParameter("username");
		String pwd = req.getParameter("password");
		Admin a = AM.get().addAdmin(un,pwd);
		AM.get().save(a);
		try {
			HttpSession session = req.getSession(true);
			session.setAttribute("currAdmin",null);
			resp.sendRedirect("/admin/index.jsp");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	
}
